package com.cgt.xiaotao.promotion.controller;

import com.cgt.common.domain.dto.PageDTO;
import com.cgt.common.utils.R;
import com.cgt.xiaotao.promotion.domain.dto.CouponFormDTO;
import com.cgt.xiaotao.promotion.domain.dto.CouponIssueFormDTO;
import com.cgt.xiaotao.promotion.domain.query.CouponQuery;
import com.cgt.xiaotao.promotion.domain.vo.CouponDetailVO;
import com.cgt.xiaotao.promotion.domain.vo.CouponPageVO;
import com.cgt.xiaotao.promotion.domain.vo.CouponVO;
import com.cgt.xiaotao.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "优惠券相关接口")
@RestController
@RequestMapping("/coupons")
@RequiredArgsConstructor
public class CouponController {

    private final ICouponService couponService;

    @ApiOperation("根据id查询优惠券接口")
    @GetMapping("/{id}")
    public R<CouponDetailVO> queryCouponById(@PathVariable("id") Long id) {
        try {
            return R.ok(couponService.queryCouponById(id));
        } catch (Exception e) {
            return R.fail("查询优惠券失败！");
        }
    }

    @ApiOperation("查询发放中的优惠券列表")
    @GetMapping("/list")
    public R<List<CouponVO>> queryIssuingCoupons() {
        try {
            return R.ok(couponService.queryIssuingCoupons());
        } catch (Exception e) {
            return R.fail("查询优惠券列表失败！");
        }
    }

}
